| 1 |  |  | import * as fs from 'fs' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | import {homedir} from 'os' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | import OS from '../client/OS' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | import {Config} from '../models/config' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | import {ensureDirectoryExists} from './filesystem' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * Get the location of the home directory of Jale. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | const jaleHomeDir = `${homedir()}/.jale` | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * Get the location of the Jale configuration. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | const jaleConfigPath = `${jaleHomeDir}/config.json` | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * Get the location of the Jale log directory. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | const jaleLogsPath = `${jaleHomeDir}/log` | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * Get the location of the Jale sites directory. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | const jaleSitesPath = `${jaleHomeDir}/sites` | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  * Get the location of the Jale certificates directory. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | const jaleSslPath = `${jaleHomeDir}/ssl` | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  * Get the location of the fallback server of Jale. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | const jaleFallbackServer = `${jaleHomeDir}/server/index.php` | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  * Get the location of the Nginx apps vhost directory. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | const jaleNginxAppsPath = `${OS.getInstance().usrLocalDir}/etc/nginx/jale/apps` | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  * Get the location of the Nginx app templates vhost directory. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | const jaleNginxAppTemplatesPath = `${OS.getInstance().usrLocalDir}/etc/nginx/jale/templates` | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  * Ensure the Jale home directory exists. If it does not exist, we'll create it. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  * Returns the current location of the Jale home directory. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | async function ensureHomeDirExists(): Promise<false | string> { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     return ensureDirectoryExists(jaleHomeDir) | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 54 |  |  | } | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  | function getConfig(): Config { | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |     const rawConfig: string = fs.readFileSync(jaleConfigPath, 'utf-8') | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |     return JSON.parse(rawConfig) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | export { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     jaleHomeDir, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     jaleConfigPath, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     jaleLogsPath, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     jaleSslPath, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     jaleSitesPath, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     jaleFallbackServer, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     jaleNginxAppsPath, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     jaleNginxAppTemplatesPath, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     ensureHomeDirExists, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     getConfig | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 72 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 73 |  |  |  |